package rpt.yto.flex.remote.data.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import rpt.yto.flex.remote.data.bean.RPTNodeBean;
import rpt.yto.flex.remote.data.dao.INodeDAO;

@SuppressWarnings("unchecked")
public class NodeDAO extends SqlMapClientDaoSupport implements INodeDAO {

	private static NodeDAO nodeDAO = new NodeDAO();
	
	private NodeDAO() {
		
	}
	
	public static final NodeDAO getInstance() {
		return nodeDAO;
	}
	
	public List<RPTNodeBean> queryNodeById(String id) throws Exception {
		return getSqlMapClientTemplate().queryForList("selNodesById", id);
	}
	
	public Object queryMaxNodePk() throws Exception {
		return getSqlMapClientTemplate().queryForObject("queryMaxNodePk");
	}
	
	public Integer queryNodeByNodeId(Map<String , String> param) throws Exception {
		return Integer.valueOf(String.valueOf(getSqlMapClientTemplate().queryForObject("queryNodeByNodeId" , param)));
	}

	@Override
	public String modifyNode(Map<String, String> param) throws Exception {
		return String.valueOf(getSqlMapClientTemplate().update("modifyNode", param));
	}

	@Override
	public void addNode(Map<String, String> param) throws Exception {
		getSqlMapClientTemplate().insert("addNode" , param);
	}

	@Override
	public String deleteNode(String pk_nodes) throws Exception {
		return String.valueOf(getSqlMapClientTemplate().delete("deleteNode" , pk_nodes));
	}

	@Override
	public boolean nextNodeExsits(String pk_nodes) throws Exception {
		
		Integer result = Integer.valueOf(String.valueOf(getSqlMapClientTemplate().queryForObject("queryNextNodeExsits", pk_nodes)));
		
		if(result > 0)
			return true;
		
		return false;
	}

	@Override
	public Integer exsitsTemplate(String nodeid) throws Exception {
		return Integer.valueOf(String.valueOf(getSqlMapClientTemplate().queryForObject("exsitsTemplate" , nodeid)));
		
	}

	@Override
	public String queryTemplateId(String nodeid) throws Exception {
		return String.valueOf(getSqlMapClientTemplate().queryForObject("queryTemplateId", nodeid));
	}

	@Override
	public String deleteTemplate(Map<String, String> param) throws Exception {
		getSqlMapClientTemplate().delete("deleteTemplate", param);
		return "true";
	}

}
